<?php
require_once("config.php");
if (false && APP_DEBUG) {
    ini_set('display_errors', 'On');
    error_reporting(E_ALL);
} else {
    error_reporting(0);
}
require_once("source/common.php");
require_once("source/myfun.php");
$tp = $_GET["tp"];
if (empty($tp)) {
    echo 'welcome';
    exit;
} else {
    if (strpos($tp, '.') !== false) {
        echo echojson('illegal access', 0);
        exit;
    }
    $tpl = init_smarty();
    $key = '2Xp95kiGn#3p';
    $uid = (int) $_GET['uid'];

    $imei = $_GET['imei'];
    $pt = $_GET['pt'];
    $ver = $_GET['ver'];
    $appid = (int) $_GET['appid'];
    $sign = $_GET['sign'];

    $time = time();
    if ($uid)
    {
    	$sql="update tttj.userinfo set last_login='$time' where id='$uid'";
    	exec_db($sql);
    	$datestr = date('Y-m-d');
    	$dblink = getdblink_tttj();
    	exec_db_ps("LOCK TABLE tttj.liucun WRITE",$dblink);

    	$sql = "select * from tttj.liucun where uid=$uid and datestr='$datestr' limit 1;";
    	$isliucun = getonerecord_ps($sql,$dblink);
    	if (!$isliucun)
    	{
    		$sql = "insert into tttj.liucun (uid,pt,imei,datestr,ontime,appid) values ($uid,$pt,'$imei','$datestr',$time,$appid);";
    		exec_db_ps($sql,$dblink);
    	}
    	exec_db_ps("unlock tables",$dblink);

	}else {
    	if ($pt==1)
    	{
    		$channel = $_GET['channel'];
    		if ($channel)
    		{
    			$datestr = date('Y-m-d');
    			$dblink = getdblink_tttj();
    			exec_db_ps("LOCK TABLE tttj.activate WRITE",$dblink);
    			$sql = "select * from tttj.activate where imei='$imei' and pt=$pt and datestr='$datestr' limit 1;";
    			$isliucun = getonerecord_ps($sql,$dblink);
    			if (!$isliucun)
    			{
    				$ip = getip();
    				$area = getiparea($ip);
    				$sql = "insert into tttj.activate (channel,imei,pt,ip,area,datestr,ontime,appid) values ('$channel','$imei',$pt,'$ip','$area','$datestr',$time,$appid);";
    				exec_db_ps($sql,$dblink);
    			}
    			exec_db_ps("unlock tables",$dblink);
    		}
    	}else {
			$sql = "select id from tttj.jfq_record where appid='{$appid}' and idfa='{$imei}'";
			$jfq_record=getonerecord($sql);
			if($jfq_record){
			    exec_db('update tttj.jfq_record set dstatus=1 where id='.$jfq_record['id']);
			}
    		//file_put_contents("/home/www/a.tttj.3z.cc/cache/active_ios.txt",$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\r\n",FILE_APPEND);
    	}
    }

    $tpl->assign("uid", $uid);
    $tpl->assign("imei", $imei);
    $tpl->assign("pt", $pt);
    $tpl->assign("ver", $ver);
    $tpl->assign("appid", $appid);
    $tpl->assign("sign", $sign);
    $tpl->assign("tp", $tp);
    if (strstr($tp, 'front') || strstr($tp, 'acts'))
    {
		if (version_compare($ver, '3.1.4', '>=')){
			paracheck($pt, $ver);
		}
    }
    if (strstr($tp, 'api'))
    {
    	header("Content-type: application/json; charset=utf-8");
    }
    if ($tp=='front/daysign' && (version_compare($ver, '2.0.2', '>=') || $uid==160689))
    {
    	$tp = 'front/daysign_new';
    }
    //$tpl->assign("iscurversion",iscurversion());
//     $testaccount = array('111459','162197','160689','191439','139776');
    $testaccount = array();
    include_once("source/{$tp}.php");
}

?>